import 'package:flutter/cupertino.dart';
import 'package:jetour_line/my_colors.dart';
import 'package:jetour_line/utils/extension_int.dart';
import '../../base_widget/base_image.dart';
import '../../base_widget/image_network_widget.dart';
import '../../utils/page_push_utils.dart';
import '../common/commonDetail/common_detail_page.dart';
import '../../models/guide_list_model.dart';
class CommonItemWidget extends StatelessWidget {
  final ListElement comment ;
  Function? collectCallBack;
  CommonItemWidget({Key? key, required this.comment,this.collectCallBack}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    String img = comment.logo;
    String caption = comment.caption;
    List<String>? tag ;
    if(comment.tag != null){
      tag = comment.tag!;
    }
    String msg = "${comment.startCity??comment.startCityName} - ${comment.endCity??comment.endCityName} · ${comment.totalDay.ceil()}天";
    String num = '${comment.clickNum}';
    return  GestureDetector(
      onTap: (){
        PagePushUtils.push(context,  CommonDetailScreen(id:  comment.id,collectCallBack: collectCallBack,));
      },
      child: Padding(
        padding: EdgeInsets.only(bottom: 20.px),
        child: Container(
          padding: EdgeInsets.all(24.px),
          height: 230.rpx,
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(4.rpx), color: MyColors.white),
          child: Row(
            children: <Widget>[
              Stack(
                children: [
                  Container(
                    width: 190.rpx, height: 180.rpx,
                    margin: EdgeInsets.only(right: 24.rpx),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(15.rpx),
                      child:
                      SizedBox(width: 190.rpx, height: 180.rpx, child: ImageNetworkWidget(img)),
                    ),
                  ),
                  if(comment.hasVideo)
                    Positioned(left: 4.px,bottom: 4.px, child: BaseImage(image: 'icon_gcvideo',width: 40.px,height: 40.px,))
                ],
              ),
              Expanded(
                  flex: 1,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        caption,
                        textAlign: TextAlign.left,
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(fontSize: 30.rpx, color: const Color(0xff333333), height: 1.5),
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          LayoutBuilder(builder: (context, constraint) {
                            final double maxWidth = constraint.maxWidth.floorToDouble();
                            final List<Widget> tagList = [];
                            double allWidth = 0;
                            if(tag != null)
                              // ignore: curly_braces_in_flow_control_structures
                              for (int i = 0; i < tag.length; i++) {
                                double tempWidth =
                                (tag.length * 20.rpx * 1.2 + 8.rpx + 16.rpx)
                                    .ceilToDouble();
                                if (allWidth + tempWidth < maxWidth) {
                                  tagList.add(Container(
                                      padding: EdgeInsets.all(8.rpx),
                                      margin: EdgeInsets.only(right: 16.rpx),
                                      decoration: BoxDecoration(
                                          color: const Color(0xFFfff0e6), borderRadius: BorderRadius.circular(6.rpx)),
                                      child: Text(
                                        tag[i],
                                        style: TextStyle(fontSize: 20.rpx, color: const Color(0xffee7219)),
                                      )));
                                  allWidth = allWidth + tempWidth;
                                }
                              }
                            return Row(children: tagList);
                          }),

                        ],
                      ),
                      Row(
                        children: [
                          Expanded(
                              child: Text(
                                msg,
                                style: TextStyle(
                                  fontSize: 26.rpx,
                                  color: const Color(0xff999999),
                                ),
                              )),

                          if(comment.clickNum!= null)
                            BaseImage(
                              image: 'ls_icon_browse',
                              width: 36.px,
                              height: 36.px,
                            ),
                          if(comment.clickNum!= null)
                            Padding(
                              padding: EdgeInsets.only(left: 12.rpx),
                              child: Text(
                                num,
                                style: TextStyle(
                                  fontSize: 24.rpx,
                                  color: const Color(0xff999999),
                                ),
                              ),
                            ),
                        ],
                      ),
                    ],
                  ))
            ],
          ),
        ),
      ),
    );
  }
  // @override
  // State<CommonItemWidget> createState() => _CommonItemWidgetState();
}

// class _CommonItemWidgetState extends State<CommonItemWidget> {
//
//
//
// }
